//
//  MemberPrepaidPhoneTableViewCell.m
//  BaseFrame
//
//  Created by 吕金状 on 2017/8/9.
//  Copyright © 2017年 com.mxh. All rights reserved.
//

#import "MemberPrepaidPhoneTableViewCell.h"

@interface MemberPrepaidPhoneTableViewCell ()

Strong UIImageView *titleImageView;
Strong UILabel *nameLabel;
Strong UILabel *titleLabel;
Strong UIButton *chooseButton; /**<*/
Strong UIView *lineView;

@end

@implementation MemberPrepaidPhoneTableViewCell

- (id)initWithCellIdentifier:(NSString *)cellID{
    self = [super initWithCellIdentifier:cellID];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        _titleImageView = [UIImageView new];
        _titleImageView.contentMode = UIViewContentModeScaleAspectFit;
        _titleImageView.image = [UIImage imageNamed:@"root_left"];
        
        _nameLabel  = [[UILabel alloc]init];
        _nameLabel.font = DEF_FontSize_14;
        _nameLabel.textColor = getColor(textColor);
        _nameLabel.text = @"充值金额";
        
        _titleLabel  = [[UILabel alloc]init];
        _titleLabel.font = [UIFont systemFontOfSize:16 weight:3];
        _titleLabel.textColor = getColor(mainColor);
        
        _chooseButton = [[UIButton alloc]init];
        [_chooseButton setImage:[UIImage imageNamed:@"choose_nor"] forState:UIControlStateNormal];
        [_chooseButton setImage:[UIImage imageNamed:@"choose_sel"] forState:UIControlStateSelected];
        [_chooseButton addTarget:self action:@selector(chooseButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        
        [self.contentView sd_addSubviews:@[_titleLabel , _titleImageView , _nameLabel , _chooseButton]];
        
        _lineView = [[UIView alloc]init];
        _lineView.backgroundColor = getColor(dividerColor);
        [self.contentView addSubview:_lineView];
        [self layoutFrame];
    }
    return self;
}

- (void)layoutFrame{
    __weak __typeof(self)weakSelf = self;
    [self.titleImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10 / WIDTH_5S_SCALE);
        make.top.mas_equalTo(10);
        make.bottom.mas_equalTo (- 10);
        make.width.mas_equalTo(3);
    }];
    
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.titleImageView.mas_right).offset(5 / WIDTH_5S_SCALE);
        make.top.mas_equalTo(0);
        make.bottom.mas_equalTo (0);
    }];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.nameLabel.mas_right).offset(20 / WIDTH_5S_SCALE);
        make.top.mas_equalTo(0);
        make.bottom.mas_equalTo (0);
    }];
    
    [self.chooseButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(- 10 / WIDTH_5S_SCALE);
        make.top.mas_equalTo((44 - 20 / WIDTH_5S_SCALE) / 2);
        make.height.mas_equalTo (20 / WIDTH_5S_SCALE);
        make.width.mas_equalTo(20 / WIDTH_5S_SCALE);
    }];
    
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10 / WIDTH_5S_SCALE);
        make.bottom.mas_equalTo(0);
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH - 20 / WIDTH_5S_SCALE, 0.5));
    }];
}

- (void)setModel:(NSDictionary *)model{
    _model = model;
    self.titleLabel.text = model[@"title"];
    if (self.chooseIndex == self.indexPath.row) {
        self.chooseButton.selected = YES;
    }else{
        self.chooseButton.selected = NO;
    }
}

#pragma mark - click

- (void)chooseButtonClick:(UIButton *)sender{
    if (_getChooseIndexClick) {
        _getChooseIndexClick();
    }
//    if (!sender.selected) {
//        
//    }else{
//        
//    }
}

@end
